package ch.usi.inf.pf2.editor;

import java.awt.Color;

import javax.swing.BorderFactory;

import ch.usi.inf.pf2.Sheet;
import ch.usi.inf.pf2.cell.Cell;
import ch.usi.inf.pf2.cell.Converter;

/**
 * Class that defines the copy action.
 * With the copy action there is no change in the text, the cell color, and 
 * the cell border; so the new ones are equal to the old ones
 * 
 * @author Lorenzo Baracchi, Ebrisa Savina Mastrodicasa
 *
 */
public class Copy extends TextManagement 
{

	/**
	 * Constructor for Copy
	 * @param sheet
	 * @param rowIndex the row index
	 * @param columnIndex the column index
	 */
	public Copy (Sheet sheet, int rowIndex, int columnIndex) 
	{
		super(sheet, rowIndex, columnIndex);
	}

	
    /**
     * Change the cell and at same time store 
     * it into oldBorder for possible undo actions.
     */
	@Override
	public void evaluate () 
	{
		Cell c=sheet.getCell(getColumnIndex(), getRowIndex());
		setOldText(c.getContent().toString());
		setNewText(c.getContent().toString()); 
		setOldColor(c.getColor());
		setNewColor(c.getColor());
		setOldBorder(c.getBorderType());
		setNewBorder(c.getBorderType());
		System.out.println("Copy evaluate: "+c.getContent().toString());
	}
	
	
	/**
	 * @return A sentence declaring the copy execute.
	 */
	public String toString ()
	{
		Converter conv = new Converter();
		conv.setCellReferenceNumbers(new int[] {this.getColumnIndex(), this.getRowIndex()});
		conv.convertToString();
		String copyString = "Copy the cell in " + conv.getCellReference();
		return copyString;
	}

	
	/**
     * Undo the previous copying of a cell.
     */
	@Override
	public void restore() 
	{
	    setOldText("");
	    setNewText("" ); 
	    setOldColor(Color.WHITE);
	    setNewColor(Color.WHITE);
	    setOldBorder(BorderFactory.createMatteBorder(2,5,2,5,Color.WHITE));
	    setNewBorder(BorderFactory.createMatteBorder(2,5,2,5,Color.WHITE));
	}

}
